//
//  NDetailsViewController.m
//  ieGou
//
//  Created by 嚷蜗痕殇心 on 15/1/28.
//  Copyright (c) 2015年 chaox. All rights reserved.
//

#import "NDetailsViewController.h"
#import "NDetaCell.h"
#import "NAddCell.h"
#import "NAddDetaCell.h"
#import "NFuJinCell.h"
#import "NDAddViewController.h"
#import "NCommentViewController.h"
#import "NearByViewController.h"
@interface NDetailsViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, retain)UITableView *tableViewA;

@end

@implementation NDetailsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    //两个按钮 (UINavigationController上)
    self.navigationItem.rightBarButtonItems = @[[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"Near8.0.png"] style:UIBarButtonItemStyleDone target:self action:@selector(naviAvtion:)],[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"Nfenxiang.png"] style:UIBarButtonItemStylePlain target:self action:@selector(twoNaviAction:)]];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemReply target:self action:@selector(buttonAction:)];
    
    [self createTableView];
    
    
}
//返回按钮
-(void)buttonAction:(UIBarButtonItem *)barButton
{
    NearByViewController *nearBY = [[NearByViewController alloc]init];
    [self.navigationController pushViewController:nearBY animated:YES];
    [nearBY release];
}
//navigation按钮
- (void)naviAvtion:(UIBarButtonItem *)barButton
{
   //收藏
//    if () {
//        <#statements#>
//    }
    
    
    
    
    
}
- (void)twoNaviAction:(UIBarButtonItem *)barButton
{
    
}
//设置UITableView
- (void)createTableView
{
  
    self.tableViewA = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    self.tableViewA.dataSource = self;
    self.tableViewA.delegate = self;
    
    UIView *aView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 375, 180)];
    UIImageView *myImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"Near1.jpg"]];
    aView.backgroundColor = [UIColor greenColor];
    myImageView.frame =CGRectMake(0, 0, 375, 180);
    [aView addSubview:myImageView];
    [myImageView release];
    self.tableViewA.tableHeaderView = aView;
    
    [self.view addSubview:_tableViewA];
    [_tableViewA release];
    
    //加在图片上的
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(30, 100, 180, 50)];
    label.backgroundColor = [UIColor cyanColor];
    [myImageView addSubview:label];
    [label release];
    
    

}
//tableView的初始化方法
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    if (indexPath.section == 0) {
        static NSString *str = @"strA";
        NDetaCell *cell = [tableView dequeueReusableHeaderFooterViewWithIdentifier:str];
        if (!cell) {
            cell = [[[NDetaCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"strA"]autorelease];
        }
        cell.contentView.backgroundColor = [UIColor whiteColor];
        cell.dqImage.image = [UIImage imageNamed:@"Near6.png"];
        cell.dqLabel.text = @"当前位置";
        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        return cell;
    }
    if (indexPath.section == 1)
    {
        static NSString *str2 = @"srr";
        NAddCell *cell = [tableView dequeueReusableHeaderFooterViewWithIdentifier:str2];
        if (cell == nil) {
            cell = [[NAddCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:str2];
        }
        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        cell.qianImage.image = [UIImage imageNamed:@"Nqian.png"];
        cell.shouLabel.text = @"已售";
        return cell;
        }
    if (indexPath.section == 2) {
       static NSString *str3 = @"stt";
        NAddDetaCell *cell = [tableView dequeueReusableHeaderFooterViewWithIdentifier:str3];
        if (cell == nil) {
            cell = [[[NAddDetaCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:str3]autorelease];
        }
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.pingLabel.text = @"查看全部";
        //cell.numLabel
        return cell;
        
    }
    if (indexPath.section == 3) {
        static NSString *str4 = @"strr";
        NFuJinCell *cell = [tableView dequeueReusableHeaderFooterViewWithIdentifier:str4];
        if (cell == nil) {
            cell = [[NFuJinCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:str4];
        }
        
        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        return cell;
    }
    
    
    return nil;
    
}
//返回的行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        
        return 1;
    }
    if(section == 1){
        return 2;
    }
    if (section == 2) {
        return 1;
    }
    if (section == 3) {
        return 3;
    }
    else
        return 1;

    
}

//返回的个数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 4;
}
//cell高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {

        return 40.f;
    } else if(indexPath.section == 1){
        
        return 90.f;
    }else if(indexPath.section == 2){
        
        return 50.f;
    }else if(indexPath.section == 3) {
        
        return 90.f;
    }
    else
        return 90.f;
}
// 分区头
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return 23.f;
    }else if(section == 1){
        return 11.f;
    }else if(section == 2){
        return 11.f;
    }else if(section == 3){
        return 11.f;
    }
        return 11.f;
}


//设置header
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0,0, 375, 30)];
    if(section == 1){
        UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(10, -17, 100, 30)]autorelease];
        label.text=@"团购";
        label.font = [UIFont systemFontOfSize:17];
        label.textColor = [UIColor lightGrayColor];
        [view addSubview:label];
    }else if(section == 2){
        UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(10,-13, 100, 18)]autorelease];
        label.text=@"评价";
        label.font = [UIFont systemFontOfSize:17];
        label.textColor = [UIColor lightGrayColor];
        [view addSubview:label];
    }else if(section == 3){
        UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(10, -13, 100, 18)]autorelease];
        label.text=@"附近团购";
        label.font = [UIFont systemFontOfSize:17];
        label.textColor = [UIColor lightGrayColor];
        [view addSubview:label];

        
    }
    return view;
}
//点击退出下一页
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        
    }
    if (indexPath.section == 1) {
        NDAddViewController *addView = [[NDAddViewController alloc]init];
        [self.navigationController pushViewController:addView animated:YES];
        [addView release];
        
    }
    if (indexPath.section == 2) {
        NCommentViewController *comView = [[NCommentViewController alloc]init];
        [self.navigationController pushViewController:comView animated:YES];
        [comView release];
    }
    if (indexPath.section == 3) {
        
        NDAddViewController *nAddView = [[NDAddViewController alloc]init];
        [self.navigationController pushViewController:nAddView animated:YES];
        [nAddView release];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
